const Base = require('./base.js');

module.exports = class extends Base {
  async cascaderAction() {
    const resData = [];
    const data = await this.model('city').select();
    for (const item of data) {
      if (item.type === 0) {
        item.children = [];
        for (const itemchild of data) {
          if (itemchild.type === 1 && itemchild.parent_code === item.code) {
            item.children.push(itemchild);
          }
        }
        resData.push(item);
      }
    }
    return this.success(resData);
  }
};
